﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace OutLook.Model.Infrastructure
{
    [DataContract]
    public class Coupla : IEquatable<Coupla>, IAssignable
    {
        #region Constructors

        /// <summary>
        /// Initializes new default instance of Coupla
        /// </summary>
        private Coupla() : this(string.Empty, 0.0d) { }

        /// <summary>
        /// Initializes new instance of Coupla
        /// </summary>
        /// <param name="element">Indicator name</param>
        /// <param name="percentage">Value of indicator</param>
        private Coupla(string indicator, double value)
        {
            Indicator = indicator;
            Value = value;
        }

        #endregion

        #region Facroty Method

        /// <summary>
        /// Creates new instance of Coupla
        /// </summary>
        /// <param name="element">Indicator name (Cann't be empty or null)</param>
        /// <param name="percentage">Value of indicator</param>
        /// <returns>New instance of Coupla</returns>
        /// <remarks>Can return NULL if was wrong input arguments</remarks>
        public static Coupla Create(string indicator, double value)
        {
            if (indicator == null || indicator.Equals(string.Empty))
                return null;

            return new Coupla(indicator, value);
        }

        #endregion

        #region IEquatable<coupla> Implementation

        /// <summary>
        /// Compares current Coupla with another one
        /// </summary>
        /// <param name="other">Another Coupla</param>
        /// <returns>True - If current Coupla and another one are equal, otherwise -False</returns>
        public bool Equals(Coupla other)
        {
            if (other == null)
                return false;

            if (Indicator.Equals(other.Indicator) && Value == other.Value)
                return true;

            return false;
        }

        #endregion

        #region IAssignable Implementation

        /// <summary>
        /// Assigns values of current Coupla to the argument object
        /// </summary>
        /// <param name="obj">Object to assign to</param>
        /// <exception cref="ArgumentNullException">If object to assign to is nullable</exception>
        /// <exception cref="NotSupportedException">If object to assign to doesn't fit</exception>
        public void AssignTo(object obj)
        {
            if (obj == null)
                throw new ArgumentNullException();

            if (obj is Coupla)
            {
                Coupla coupla = obj as Coupla;
                coupla.Value = Value;
                coupla.Indicator = Indicator;

                return;
            }

            throw new NotSupportedException();
        }

        #endregion

        #region Properties

        [DataMember(Order = 1)]
        /// <summary>
        /// The Indicator
        /// </summary>
        public string Indicator { get; set; }

        [DataMember(Order = 2)]
        /// <summary>
        /// The Value of of indicator
        /// </summary>
        public double Value { get; set; }

        #endregion

    }
}
